package com.example.module_motorcircle.widget.nine_pics

import android.graphics.Rect
import android.view.View
import androidx.core.provider.FontsContractCompat.Columns
import androidx.recyclerview.widget.RecyclerView

/**
 * @author yaotianxue
 * @description 自定义分割线
 * @date 2025/2/12
 */
class SpaceItemDecoration(private val space:Int,private val column:Int = 3):RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        super.getItemOffsets(outRect, view, parent, state)
        //下标
        val position = parent.getChildLayoutPosition(view)
        //默认间隔
        outRect.left = space/2
        outRect.top = space/2
        outRect.right = space/2
        outRect.bottom = space/2
        //第一列
        if(position % column == 0){
            outRect.left = space
        }
        //最后一列
        if(position % column == 2){
            outRect.right = space
        }
        //第一行
        if(position < column){
            outRect.top = space
        }
        //最后一行  总数8 列表3
        val rows = parent.childCount / column
        if(position >= column*(rows-1)){
            outRect.bottom = space
        }
    }
}